home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-wos-src / pasm / errors.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  8KB  |  225 lines

  1. /* $VER: pasm errors.c V1.1a (20.06.98)
  2.  *
  3.  * This file is part of pasm, a portable PowerPC assembler.
  4.  * Copyright (c) 1997-98  Frank Wille
  5.  *
  6.  * pasm is freeware and part of the portable and retargetable ANSI C
  7.  * compiler vbcc, copyright (c) 1995-98 by Volker Barthelmann.
  8.  * pasm may be freely redistributed as long as no modifications are
  9.  * made and nothing is charged for it. Non-commercial usage is allowed
  10.  * without any restrictions.
  11.  * EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
  12.  * SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
  13.  *
  14.  *
  15.  * v1.1a  (20.06.98) phx
  16.  *        Warning 58, if rA=rD for an update instruction.
  17.  * v1.1   (19.06.98) phx
  18.  *        Error 46 changed into a warning (wrong base register for
  19.  *        accessing a relocatable symbol).
  20.  * v0.7   (02.01.98) phx
  21.  *        Deleted "EHF" in warning 52.
  22.  * v0.6   (30.10.97) phx
  23.  *        New error messages.
  24.  * v0.5   (12.10.97) phx
  25.  *        New error messages.
  26.  * v0.4   (05.07.97) phx
  27.  *        Program returns EXIT_FAILURE if an error occurs.
  28.  *        New error messages. Error 33 is a warning now.
  29.  * v0.2   (25.03.97) phx
  30.  *        Writes ELF object for 32-bit PowerPC big-endian. Either absolute
  31.  *        or ELF output format may be selected. ELF is default for all
  32.  *        currently supported platforms. PPCasm supports nine different
  33.  *        relocation types (there are much more...).
  34.  *        Compiles and works also under NetBSD/amiga (68k).
  35.  *        Changed function declaration to 'new style' in all sources
  36.  *        (to avoid problems with '...' for example).
  37.  *        Warnings can be disabled.
  38.  * v0.1   (11.03.97) phx
  39.  *        First test version with all PowerPC instructions and most
  40.  *        important directives. Only raw, absolute output.
  41.  * v0.0   (14.02.97) phx
  42.  *        File created. Project started.
  43.  */
  44.  
  45.  
  46. #define ERRORS_C
  47. #include "ppcasm.h"
  48.  
  49.  
  50. /* error flags */
  51. #define EF_NONE 0
  52. #define EF_WARNING 1
  53. #define EF_ERROR 2
  54. #define EF_FATAL 3
  55. #define EF_TYPEMASK 0xf
  56.  
  57. #define EF_NOLINE 0x10
  58.  
  59.  
  60. void error(int,...);
  61. void ierror(char *,...);
  62.  
  63.  
  64.  
  65. static struct {
  66.   char *txt;
  67.   int flags;
  68. } errors[] = {
  69.   "No error",EF_NONE|EF_NOLINE,
  70.   "Out of memory",EF_FATAL|EF_NOLINE,                               /* 01 */
  71.   "Missing source file name",EF_FATAL|EF_NOLINE,
  72.   "Missing output file name",EF_FATAL|EF_NOLINE,
  73.   "Multiple source file names detected",EF_FATAL|EF_NOLINE,
  74.   "File \"%s\" has a read error",EF_FATAL|EF_NOLINE,                /* 05 */
  75.   "Can't open \"%s\"",EF_FATAL|EF_NOLINE,
  76.   "Symbol \"%s\" defined twice",EF_ERROR,
  77.   "Macro \"%s\" defined twice",EF_ERROR,
  78.   "Reference to undefined macro parameter \\%d",EF_ERROR,
  79.   "Unknown opcode \"%s\"",EF_ERROR,                                 /* 10 */
  80.   "Too many macro parameters",EF_ERROR,
  81.   "Colon expected",EF_ERROR,
  82.   "Syntax error",EF_ERROR,
  83.   "String constant expected",EF_ERROR,
  84.   "Illegal section attribute \"%c\"",EF_ERROR,                      /* 15 */
  85.   "Section attributes don't match",EF_ERROR,
  86.   "Missing argument",EF_ERROR,
  87.   "Extra characters on line",EF_ERROR,
  88.   "Undefined symbol",EF_ERROR,
  89.   "Double unary operator",EF_ERROR,                                 /* 20 */
  90.   "Missing closing parenthesis",EF_ERROR,
  91.   "Illegal operation for a reloc expression",EF_ERROR,
  92.   "Symbols reside in different sections",EF_ERROR,
  93.   "Constant integer expression required",EF_ERROR,
  94.   "Unable to create output file \"%s\"",EF_FATAL|EF_NOLINE,         /* 25 */
  95.   "Error while writing to \"%s\"",EF_FATAL|EF_NOLINE,
  96.   "Instruction has too few operands",EF_ERROR,
  97.   "Can't assign external symbol",EF_ERROR,
  98.   "Can't assign reloc half word",EF_ERROR,
  99.   "Immediate operand doesn't fit into %d bits",EF_WARNING,          /* 30 */
  100.   "Register operand out of range",EF_ERROR,
  101.   "Reloc symbol required",EF_ERROR,
  102.   "Branch destination is not in current section",EF_WARNING,
  103.   "Branch operand out of range",EF_ERROR,
  104.   "CR-specifier out of range",EF_ERROR,                             /* 35 */
  105.   "Operand field \"%s\" out of range",EF_ERROR,
  106.   "\"%s\" is a 64-bit instruction",EF_WARNING,
  107.   "\"%s\" is an optional instruction",EF_WARNING,
  108.   "\"%s\" is a supervisor-level instruction",EF_WARNING,
  109.   "\"(rA)\" expected, after index expression",EF_ERROR,             /* 40 */
  110.   "Expression must be dividable by four",EF_ERROR,
  111.   "Invalid register field mask",EF_ERROR,
  112.   "Maximum nesting depth for conditional assembly exceeded",EF_ERROR,
  113.   "%s without matching .if",EF_ERROR,
  114.   "\"fail\" directive encountered",EF_FATAL,                        /* 45 */
  115.   "Wrong base register for base relative reloc symbol access",EF_WARNING,
  116.   "Section \"%s\" was never defined",EF_ERROR,
  117.   "Option -%c: argument expected",EF_FATAL|EF_NOLINE,
  118.   "Unknown output format (%d)",EF_FATAL|EF_NOLINE,
  119.   "\"%s\" is not a section base address",EF_ERROR,                  /* 50 */
  120.   "Maximum of %d include paths reached. Path \"%s\" was ignored",
  121.     EF_ERROR|EF_NOLINE,
  122.   "Section \"%s\" with type #%d is not supported and was "
  123.     "changed to HUNK_DATA.",EF_WARNING|EF_NOLINE,
  124.   "Unsupported relocation type %s at offset %d in section \"%s\"",
  125.     EF_ERROR|EF_NOLINE,
  126.   "Option -%c: integer expected",EF_FATAL|EF_NOLINE,
  127.   "Absolute output doesn't allow external references. Symbol "      /* 55 */
  128.    "referenced was: %s",EF_ERROR|EF_NOLINE,
  129.   "Option -%c: symbol name expected",EF_FATAL|EF_NOLINE,
  130.   "Unknown assembler mode -m%s",EF_WARNING|EF_NOLINE,
  131.   "r%d used as source and as destination register in an update "
  132.    "instruction",EF_WARNING,
  133. };
  134.  
  135.  
  136. void error(int errn,...)
  137. /* prints errors and warnings */
  138. {
  139.   struct GlobalVars *gv = &gvars;
  140.   va_list vl;
  141.   char *errtype;
  142.   int flags = errors[errn].flags;
  143.   struct SourceThread *mst,*st = gv->cthread;
  144.  
  145.   if (((flags&EF_TYPEMASK) == EF_WARNING) && gv->dontwarn)
  146.     return;
  147.   switch(flags&EF_TYPEMASK) {
  148.     case EF_WARNING:
  149.       errtype = "Warning";
  150.       break;
  151.     case EF_ERROR:
  152.       gv->returncode = EXIT_FAILURE;
  153.       errtype = "Error";
  154.       break;
  155.     case EF_FATAL:
  156.       gv->returncode = EXIT_FAILURE;
  157.       errtype = "Fatal error";
  158.       break;
  159.     default:
  160.       ierror("Illegal error type %d",flags&EF_TYPEMASK);
  161.       gv->returncode = EXIT_FAILURE;
  162.       errtype = "";
  163.       break;
  164.   }
  165.   if (!(flags&EF_NOLINE))
  166.     printf("\n%s\n",st->lineptr);  /* display error line */
  167.  
  168.   /* print error message */
  169.   printf("%s %d: ",errtype,errn);
  170.   va_start(vl,errn);
  171.   vprintf(errors[errn].txt,vl);
  172.   va_end(vl);
  173.   
  174.   if (!(flags&EF_NOLINE)) {
  175.     if (st->macro) {
  176.       mst = st;
  177.       do
  178.         if (!(mst = mst->prev))
  179.           ierror("There's no source text where macro \"%s\" is "
  180.                  "called from",st->csource->name);
  181.       while (mst->macro);
  182.       printf(" in line %d of macro \"%s\", called from line %d of "
  183.              "file \"%s\"",(int)st->line,st->csource->name,
  184.              (int)mst->line,mst->csource->name);
  185.     }
  186.     else
  187.       printf(" in line %d of file \"%s\"",(int)st->line,st->csource->name);
  188.   }
  189.   printf(".\n");
  190.  
  191.   switch(flags&EF_TYPEMASK) {
  192.     case EF_ERROR:
  193.       /* check if maximum number of errors reached */
  194.       if (++gv->errcnt >= gv->maxerrors) {
  195.         gv->errcnt = 0;
  196.         printf("Do you want to continue (y/n) ? ");
  197.         fflush(stdin);
  198.         if (toupper((unsigned char)getchar()) == 'N')
  199.           cleanup(gv);
  200.       }
  201.       break;
  202.     case EF_FATAL:
  203.       printf("Aborting.\n");  /* fatal error aborts the assembler */
  204.       cleanup(gv);
  205.       break;
  206.   }
  207. }
  208.  
  209.  
  210. void ierror(char *errtxt,...)
  211. /* display internal error and quit */
  212. {
  213.   struct GlobalVars *gv = &gvars;
  214.   struct SourceThread *st = gv->cthread;
  215.   va_list vl;
  216.  
  217.   printf("\nINTERNAL ERROR: ");
  218.   va_start(vl,errtxt);
  219.   vprintf(errtxt,vl);
  220.   va_end(vl);
  221.   printf(" in line %d of \"%s\".\nAborting.\n",(int)st->line,
  222.          st->csource->name);
  223.   cleanup(gv);
  224. }
  225.